<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.11"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>

    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }

        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }

        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }

        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            padding-left: 7px;
            padding-right: 20px;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理<small>预约订单管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约订单管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <div class="block">
                    <el-date-picker
                            v-model="queryTime"
                            type="daterange"
                            align="right"
                            unlink-panels
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            :picker-options="pickerOptions">
                    </el-date-picker>


                    <el-select v-model="orderType" clearable placeholder="预约类型">
                        <el-option
                                v-for="item in orderTypes"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                        </el-option>
                    </el-select>

                    <el-select v-model="selectOrderStatus" clearable placeholder="预约状态">
                        <el-option
                                v-for="item in orderStatuses"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                        </el-option>
                    </el-select>
                    <el-input placeholder="会员姓名/手机号" v-model="pagination.queryString" style="width: 200px;"
                              class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                    <el-button @click="findPage()" class="dalfBut">查询</el-button>
                    <el-button type="primary" class="butT" @click="handleOrder()">预约</el-button>
                    <el-button type="primary" class="butT" @click="handleClear()">清除</el-button>
                </div>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="name" label="会员姓名" align="center"></el-table-column>
                <el-table-column prop="phoneNum" label="电话号码" align="center"></el-table-column>

                <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column prop="orderStatus" label="预约状态" align="center">

                    <template slot-scope="scope">
                        {{scope.row.orderStatus}}
                        <el-switch
                                v-model="scope.row.orderStatus"
                                active-color="#13ce66"
                                inactive-color="#ff4949"
                                on-text="未到诊"
                                off-text="已完成"
                                @change="changeStatus(scope.row)"
                                active-value="未到诊"
                                inactive-value="已完成">
                        </el-switch>
                    </template>
                </el-table-column>
                <el-table-column prop="mealName" label="套餐名称" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button @click="handleEditOrder(scope.row)" type="primary" size="mini">编辑</el-button>
                        <el-button @click="handleDelete(scope.row)" type="danger" size="mini">删除</el-button>
                    </template>

                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                                         label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="机构电话" prop="organPhoneNum">
                                                <el-input v-model="formData.organPhoneNum"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="预约日期" prop="orderDate">
                                                <el-col :span="20">
                                                    <el-date-picker
                                                            type="date"
                                                            placeholder="选择日期" v-model="formData.orderDate"
                                                            style="width: 100%;"/>
                                                </el-col>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="姓名" prop="name">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="手机号码" prop="phoneNum">
                                                <el-input v-model="formData.phoneNum"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>套餐编码</th>
                                            <th>套餐名称</th>
                                            <th>套餐说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td width="90">
                                                <input :id="c.id" v-model="setmealIds" type="checkbox" :value="c.id">
                                            </td>
                                            <td width="115"><label :for="c.id">{{c.code}}</label></td>
                                            <td width="180"><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.remark}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!--编辑标签弹层-->
            <div class="add-form">
                <el-dialog title="编辑预约" :visible.sync="editDialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right"
                                         label-width="100px">
                                    <el-row>

                                        <el-col :span="10">
                                            <el-form-item label="会员姓名" prop="member">
                                                <el-input v-model="formData.member"/>
                                            </el-form-item>
                                        </el-col>

                                        <el-col :span="12">
                                            <el-form-item label="预约日期" prop="orderDate">
                                                <el-col :span="17">
                                                    <el-date-picker
                                                            type="date"
                                                            placeholder="选择日期" v-model="formData.orderDate"
                                                            style="width: 100%;"/>
                                                </el-col>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>

                                        <el-col :span="20">
                                            &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp预约状态&nbsp&nbsp
                                            <el-select v-model="formData.orderStatus" clearable placeholder="预约状态">
                                                <el-option
                                                        v-for="item in orderStatuses"
                                                        :key="item.value"
                                                        :label="item.label"
                                                        :value="item.value">
                                                </el-option>
                                            </el-select>

                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="订单信息" name="second">
                                <div style="height: 150px">

                                    <!--<table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>订单编号</th>
                                            <th>预约类型</th>
                                            <th>预约日期</th>
                                            <th>创建时间</th>
                                            <th>预约套餐</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td width="90">
                                                <input :id="c.id" v-model="setmealIds" type="checkbox" :value="c.id">
                                            </td>
                                            <td width="115"><label :for="c.id">{{c.code}}</label></td>
                                            <td width="180"><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.remark}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>-->
                                    <el-row :gutter="15">
                                        <el-col :span="6"><div class="grid-content bg-purple" style="color:#606266 ;font-size: 18px">&nbsp</div></el-col>
                                    </el-row>
                                    <el-row :gutter="15" type="flex" align="middle">
                                        <el-col :span="6" push="2"><div  style="color:#909399 ;font-size: 14px">会员姓名 :</div></el-col>
                                        <el-col :span="6" pull="2"><div style="color:#909399 ;font-size: 14px">&nbsp&nbsp  {{formData.member}}</div></el-col>
                                        <el-col :span="6" ><div  style="color:#909399 ;font-size: 14px">预约电话 :</div></el-col>
                                        <el-col :span="6" pull="4"><div  style="color:#909399 ;font-size: 14px"> &nbsp&nbsp {{formData.phoneNumber}}</div></el-col>
                                    </el-row>
                                    <el-row :gutter="15">
                                        <el-col :span="6"><div class="grid-content bg-purple" style="color:#606266 ;font-size: 18px">&nbsp</div></el-col>
                                    </el-row>
                                    <el-row :gutter="12" type="flex" align="middle">
                                        <el-col :span="6" push="2"><div  style="color:#909399 ;font-size: 14px">预约日期 :</div></el-col>
                                        <el-col :span="6" pull="2"><div style="color:#909399 ;font-size: 14px"> &nbsp&nbsp {{formData.orderDate}}</div></el-col>
                                        <el-col :span="6" ><div  style="color:#909399 ;font-size: 14px">预约方式 :</div></el-col>
                                        <el-col :span="6" pull="4"><div  style="color:#909399 ;font-size: 14px"> &nbsp&nbsp {{formData.orderType}}</div></el-col>
                                    </el-row>
                                    <el-row :gutter="15">
                                        <el-col :span="6"><div class="grid-content bg-purple" style="color:#303133 ;font-size: 18px">&nbsp</div></el-col>
                                    </el-row>
                                    <el-row :gutter="12" type="flex" align="middle">

                                        <el-col :span="6" push="2" ><div  style="color:#909399 ;font-size: 14px">机构地址 :</div></el-col>
                                        <el-col :span="6" pull="2"><div  style="color:#909399 ;font-size: 14px"> &nbsp&nbsp {{formData.address}}</div></el-col>
                                        <el-col :span="6" ><div  style="color:#909399 ;font-size: 14px; vertical-align: top">预约套餐 :</div></el-col>
                                        <el-col :span="6" pull="4"><div  style="color:#909399 ;font-size: 14px ; text-align: center ;vertical-align: bottom"> &nbsp&nbsp {{formData.setmeal}}</div></el-col>
                                    </el-row>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="editDialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    var vue = new Vue({
        el: '#app',
        data: {
            activeName: 'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 100,
                queryString: null,
            },
            // orderStatus:null,
            lastOrderDate: "",//修改前的预约日期
            orderId: 0,//要修改的订单id
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData: [],//添加表单窗口中检查组列表数据
            setmealIds: [],//添加表单窗口中套餐复选框对应id
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            editDialogFormVisible: false,//控制编辑窗口显示/隐藏
            rules: {//校验规则
                phoneNum: [{required: true, message: '手机号为必填项', trigger: 'blur'}],
                name: [{required: true, message: '姓名为必填项', trigger: 'blur'}],
                member: [{required: true, message: '会员姓名为必填项', trigger: 'blur'}],
                orderDate: [{required: true, message: '预约日期为必填项', trigger: 'blur'}],
                orderStatus: [{required: true, message: '预约状态为必填项', trigger: 'blur'}],
            },

            //日历输入框控件
            pickerOptions: {
                shortcuts: [{
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
            queryTime: '',
            //预约类型下拉框
            orderTypes: [
                {
                    value: '微信预约',
                    label: '微信预约'
                },
                {
                    value: '电话预约',
                    label: '电话预约'
                }
            ],
            orderType: '',
            //预约状态下拉框
            orderStatuses: [
                {
                    value: '未到诊',
                    label: '未到诊'
                }, {
                    value: '已完成',
                    label: '已完成'
                }
            ],
            selectOrderStatus: '',
        },
        created() {
            this.findPage();
        },
        methods: {
            resetForm() {
                this.activeName = 'first';
                this.formData = {};
                this.setmealIds = [];
            },

            //分页查询
            findPage() {
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    orderType: this.orderType,
                    queryTime: this.queryTime,
                    orderStatus: this.selectOrderStatus,
                    queryString: this.pagination.queryString,
                }
                axios.post("/order/findPage.do", param,).then((response) => {
                    this.dataList = response.data.rows;
                    this.pagination.total = response.data.total;
                });
            },

            //弹出新增预约框并显示预约套餐列表
            handleOrder() {
                this.resetForm();
                this.dialogFormVisible = true;
                axios.post("/setmeal/findAll.do").then((response) => {
                    if (response.data.flag) {
                        this.tableData = response.data.data;
                    } else {
                        this.$message.error(response.data.message);
                    }
                });
            },

            //清除所有查询框内容
            handleClear() {
                this.queryTime = '';
                this.orderType = '';
                this.orderStatus = '';
                this.pagination.queryString = '';
            },

            //提交预约信息，进行预约
            handleAdd() {
                this.$refs["dataAddForm"].validate((valid) => {
                    if (valid) {
                        if (this.setmealIds == null || this.setmealIds.length <= 0) {
                            this.$message.error("请选择预约套餐");
                            return;
                        }
                        ;
                        axios.post("/order/orderByCall.do?setmealIds=" + this.setmealIds, this.formData).then((response) => {
                            if (response.data.flag) {
                                this.$message({
                                    type: 'success',
                                    message: response.data.message
                                });
                            } else {
                                this.$message.error(response.data.message);
                            }
                        }).finally(() => {
                            this.dialogFormVisible = false;
                            this.findPage();
                        });
                    } else {
                        this.$message.error("请正确填写预约信息");
                    }
                });

            },

            //页码更新分页查询
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },

            //弹出编辑框
            handleEditOrder(row) {
                this.activeName='first',
                this.orderId = row.id;
                axios.post("/order/findById.do?id=" + row.id).then((response) => {
                    if (response.data.flag) {
                        this.formData = response.data.data;
                        this.lastOrderDate = row.orderDate;
                        this.editDialogFormVisible = true;
                    } else {
                        this.$message.error("获取数据失败，请刷新页面重试");
                    }
                });
            },

            //提交编辑后的预约信息进行更新
            handleEdit() {
                this.$refs['dataEditForm'].validate((valid) => {
                    if (valid) {
                        axios.post("/order/update.do?id=" + this.orderId, this.formData).then((response) => {
                            if (response.data.flag) {
                                this.$message({
                                    type: 'success',
                                    message: response.data.message
                                });
                                axios.post("/ordersetting/updateReservationByDate.do?orderDate=" + this.lastOrderDate).then(() => {

                                });
                                this.findPage();
                                this.editDialogFormVisible = false;
                            } else {
                                this.$message.error(response.data.message);
                            }
                        });
                    } else {
                        this.$message.error("请正确填写预约信息");
                    }
                });
            },

            //删除预约
            handleDelete(row) {
                if(row.orderStatus=='未到诊'){
                    this.$message.error("此订单未完成，请勿删除");
                    return;
                }
                this.$confirm("确认删除此预约吗？", "提示", {type: 'warning'}).then(() => {
                    axios.post("/order/delete.do?id=" + row.id).then((reponse) => {
                        if (reponse.data.flag) {
                            this.$message({
                                type: 'success',
                                message: reponse.data.message
                            });
                            this.findPage();
                        } else {
                            this.$message.error(response.data.message);
                        }
                    });
                });
            },

            changeStatus(row) {
                var param={
                    id:row.id,
                    orderStatus:row.orderStatus,
                };
                axios.post("/order/changeOrderStatus.do",param).then((response)=>{
                    if(!response.data.flag){
                        this.$message.error(response.data.message);
                    }
                });

            }
        },


    })

</script>
</html>
